package com.jsftoolkit.gen.info;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.faces.component.UIInput;

import com.jsftoolkit.base.ResourceInfo;
import com.jsftoolkit.utils.Utils;

public class RendererInfo extends ChildInfo {

	private Set<ResourceInfo> includes = new LinkedHashSet<ResourceInfo>();

	private String templateEncoding = "UTF-8";

	private List<String> templates = new ArrayList<String>();

	private Set<String> attribs = new HashSet<String>();

	private String decodeParam;

	public RendererInfo() {
		super();
	}

	public RendererInfo(String _package, String className,
			String templateEncoding, String template, boolean _abstract,
			String... attribs) {
		super(_package, className, _abstract);
		this.templateEncoding = templateEncoding;
		this.templates.add(template);
		for (String attrib : attribs) {
			this.attribs.add(attrib);
		}
	}

	public RendererInfo(ComponentInfo component) {
		super(component);
	}

	public Set<ResourceInfo> getIncludes() {
		return includes;
	}

	public void setIncludes(Set<ResourceInfo> includes) {
		this.includes = includes;
	}

	public List<String> getTemplates() {
		return templates;
	}

	public void setTemplates(List<String> templates) {
		if (templates != null) {
			this.templates = templates;
		}
	}

	public String getTemplateEncoding() {
		return templateEncoding;
	}

	public void setTemplateEncoding(String templateEncoding) {
		if (templateEncoding != null) {
			this.templateEncoding = templateEncoding;
		}
	}

	public Set<String> getAttribs() {
		return attribs;
	}

	public void setAttribs(Set<String> attribs) {
		this.attribs = attribs;
	}

	/**
	 * 
	 * @return the name of the request parameter to decode (i.e. the value of
	 *         the parameter will be passed as the argument to
	 *         {@link UIInput#setSubmittedValue(Object)}). May contain property
	 *         substitutions (e.g. ${id})
	 */
	public String getDecodeParam() {
		return decodeParam;
	}

	public void setDecodeParam(String decodeParam) {
		this.decodeParam = decodeParam;
	}

	@Override
	public String getClassName() {
		return Utils.getValue(super.getClassName(),
				getComponent() == null ? null : getDefaultClassName()
						+ nameSuffix());
	}

	@Override
	public String getActualClassName() {
		return super.getActualClassName() == null && getComponent() != null ? getDefaultClassName()
				: super.getActualClassName();
	}

	protected String getDefaultClassName() {
		return "Html" + getComponent().getActualClassName() + "Renderer";
	}

	public void addAttribute(String o) {
		attribs.add(o);
	}

	public void addInclude(ResourceInfo o) {
		includes.add(o);
	}

	public void addTemplate(String template) {
		templates.add(template);
	}
}
